package com.hschinese.pronunciation.widget;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Color;
import android.graphics.Typeface;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.ScaleAnimation;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hschinese.pronunciation.R;
import com.hschinese.pronunciation.activity.StudyActivity;
import com.hschinese.pronunciation.activity.ToneCheckReportActivity;
import com.hschinese.pronunciation.bean.AnswerRecordBean;
import com.hschinese.pronunciation.bean.AppDataBean;
import com.hschinese.pronunciation.bean.AppResourceMap;
import com.hschinese.pronunciation.bean.TestResultBean;
import com.hschinese.pronunciation.db.DBHelper;
import com.hschinese.pronunciation.interfaces.LessonProgressInterface;
import com.hschinese.pronunciation.interfaces.NextLessonInterface;
import com.hschinese.pronunciation.utils.AnimatorUtil;
import com.hschinese.pronunciation.utils.HsSoundUtil;
import com.hschinese.pronunciation.utils.Logger;
import com.hschinese.pronunciation.utils.SimpleRecordUtil;
import com.hschinese.pronunciation.utils.Utils;

import java.util.ArrayList;
import java.util.List;

import studychinese.model.TextRecultBean;
import studychinese.model.UserBean;
import studychinese.utils.ToastUtils;

import static com.hschinese.pronunciation.R.id.practise_words;

/**
 * Created by zf on 2018/1/17.
 */

public class DictationPracticeView extends LinearLayout implements View.OnClickListener {
    private Activity mContext;
    private PlayControlView mPlayView;
    private TextView mPinyinView;
    private View mView;
    private View firstToneView, secondToneView;
    private TextView firstToneText, secondToneText;
    private ImageView firstToneOne, firstToneTwo, firstToneThree, firstToneFour, firstToneFive;
    private ImageView secondToneOne, secondToneTwo, secondToneThree, secondToneFour, secondToneFive;
    private View chooseView;

    private Cursor cursor;
    private int lessonType = 1;
    private int currentPosition = 0;
    private List<AppDataBean> mDataList;
    private int rightToneOne = 1;
    private int rightToneTwo = 1;
    private int choosedToneOne = -1;
    private int choosedToneTwo = -1;

    private LessonProgressInterface mListener = null;
    private NextLessonInterface mNextListener = null;
    private String mMp3SourceDir = null;
    private final LinearLayout ll_dication_practice;
    private final EditText edit_text_view;
    boolean flag=false;//标记edittext不会死循环
    List<TextView> textviews = new ArrayList<>();
    List<View> views = new ArrayList<>();
   public String inputcontent="";
    String toneUP="";
    String tonedown="";
    private View view_input_dictation;

    public DictationPracticeView(Context context) {
        super(context);
        Typeface type = Typeface.createFromAsset(getContext().getAssets(), "fonts/hanyupinyin.ttf");
        mContext = (Activity)context;
        mView = LayoutInflater.from(context).inflate(R.layout.dictation_practice_layout, null);
        mPlayView = (PlayControlView)mView.findViewById(R.id.practise_play_control);
        ll_dication_practice = (LinearLayout)mView.findViewById(R.id.ll_dication_practice);
        edit_text_view = (EditText)mView.findViewById(R.id.edit_text_view);
        mPlayView.setPlayRecordVisibility(View.GONE);
        mPlayView.setRecordVisibility(View.GONE);
        mPinyinView = (TextView)mView.findViewById(practise_words);
        mPinyinView.setTypeface(type);
        chooseView = mView.findViewById(R.id.practise_bottom);
        firstToneView = mView.findViewById(R.id.first_word_layout);
        firstToneText = (TextView)firstToneView.findViewById(R.id.practise_word);
        firstToneText.setTypeface(type);
        firstToneOne = (ImageView)firstToneView.findViewById(R.id.tone_1);
        firstToneTwo = (ImageView)firstToneView.findViewById(R.id.tone_2);
        firstToneThree = (ImageView)firstToneView.findViewById(R.id.tone_3);
        firstToneFour = (ImageView)firstToneView.findViewById(R.id.tone_4);
        firstToneFive = (ImageView)firstToneView.findViewById(R.id.tone_5);
        secondToneView = mView.findViewById(R.id.second_word_layout);
        secondToneText = (TextView)secondToneView.findViewById(R.id.practise_word);
        secondToneText.setTypeface(type);
        secondToneOne = (ImageView)secondToneView.findViewById(R.id.tone_1);
        secondToneTwo = (ImageView)secondToneView.findViewById(R.id.tone_2);
        secondToneThree = (ImageView)secondToneView.findViewById(R.id.tone_3);
        secondToneFour = (ImageView)secondToneView.findViewById(R.id.tone_4);
        secondToneFive = (ImageView)secondToneView.findViewById(R.id.tone_5);

        checkTone();
        this.addView(mView);
    }

    private void setEditTextListener(final int picname) {
        if(picname>0){
            ll_dication_practice.removeAllViews();
            edit_text_view.setCursorVisible(true);//隐藏光标
            edit_text_view.setFocusable(true);
            edit_text_view.setFocusableInTouchMode(true);
            edit_text_view.requestFocus();
            textviews.clear();
            views.clear();
            for (int i = 0; i <picname ; i++) {
                View mRelativeLayout = (View) View.inflate(mContext, R.layout.textview, null);
                TextView viewById = (TextView) mRelativeLayout.findViewById(R.id.tv_dictation_practice);
                view_input_dictation = (View) mRelativeLayout.findViewById(R.id.view_input_dictation);
                textviews.add(viewById);
                views.add(view_input_dictation);
                mRelativeLayout.setLayoutParams(new LinearLayout.LayoutParams(100, LinearLayout.LayoutParams.MATCH_PARENT));
                ll_dication_practice.addView(mRelativeLayout);
            }

            edit_text_view.addTextChangedListener(new TextWatcher() {

                @Override
                public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

                }

                @Override
                public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

                }

                @Override
                public void afterTextChanged(Editable editable) {

                    AppDataBean data = mDataList.get(currentPosition);
                    String inputContents = edit_text_view.getText().toString();
                    if (inputContents.length() >= data.getPinyin().replace("|","").length()) {
                        ToastUtils.showShort("輸入完成");
                        if(inputcontent.equals("")){
                            inputcontent=inputContents;
                        }else {

                        }
                        for (int i = 0; i < textviews.size(); i++) {

                            if(data.getPhone().replace("|","").equals(inputContents)){
                                    textviews.get(i).setTextColor(Color.BLUE);
                                views.get(i).setBackgroundColor(Color.BLUE);
                            }else {
                                    textviews.get(i).setTextColor(Color.RED);
                                views.get(i).setBackgroundColor(Color.RED);
                            }

                        }

                        checkInput();
                    } else {

                    }


                    for (int i = 0; i < textviews.size(); i++) {
                        if (i < inputContents.length()) {
                            textviews.get(i).setText(String.valueOf(inputContents.charAt(i)));
                        } else {
                            textviews.get(i).setText("");

                        }
                    }



                }

            });
        }

    }


    private void checkInput(){

       AppDataBean data = mDataList.get(currentPosition);
       String tone = data.getTone();
        if(lessonType==8){
            if(!toneUP.equals("") && !inputcontent.equals("")){
                mPinyinView.setVisibility(VISIBLE);
            }else {
                mPinyinView.setVisibility(INVISIBLE);
            }
        }else {
            if(!toneUP.equals("") && !inputcontent.equals("") && !tonedown.equals("")){
                mPinyinView.setVisibility(VISIBLE);
            }else {
                mPinyinView.setVisibility(INVISIBLE);
            }
        }

   }

    private void checkTone() {
        firstToneOne.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                resetFirstToneImg();
                choosedToneOne = 1;
                checkResult(firstToneOne, choosedToneOne, rightToneOne, true, 1);
                Logger.e("click 1 - 1");
                if(toneUP.equals("")){
                    toneUP="1";
                }
                checkInput();
            }
        });
        firstToneTwo.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                resetFirstToneImg();
                choosedToneOne = 2;
                checkResult(firstToneTwo, choosedToneOne, rightToneOne, true, 2);
                Logger.e("click 1 - 2");
                if(toneUP.equals("")){
                    toneUP="2";
                }
                checkInput();
            }
        });
        firstToneThree.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                resetFirstToneImg();
                choosedToneOne = 3;
                checkResult(firstToneThree, choosedToneOne, rightToneOne, true, 3);
                Logger.e("click 1 - 3");
                if(toneUP.equals("")){
                    toneUP="3";
                }
                checkInput();
            }
        });
        firstToneFour.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                resetFirstToneImg();
                choosedToneOne = 4;
                checkResult(firstToneFour, choosedToneOne, rightToneOne, true, 4);
                Logger.e("click 1 - 4");
                if(toneUP.equals("")){
                    toneUP="4";
                }
                checkInput();
            }
        });
        firstToneFive.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                resetFirstToneImg();
                choosedToneOne = 5;
                checkResult(firstToneFive, choosedToneOne, rightToneOne, true, 5);
                Logger.e("click 1 - 4");
                if(toneUP.equals("")){
                    toneUP="5";
                }
                checkInput();
            }
        });

        secondToneOne.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                resetSecondToneImg();
                choosedToneTwo = 1;
                checkResult(secondToneOne, choosedToneTwo, rightToneTwo, false, 1);
                Logger.e("click 2 - 1");
                if(tonedown.equals("")){
                    tonedown="1";
                }
                checkInput();
            }
        });
        secondToneTwo.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                resetSecondToneImg();
                choosedToneTwo = 2;
                checkResult(secondToneTwo, choosedToneTwo, rightToneTwo, false, 2);
                Logger.e("click 2 - 2");
                if(tonedown.equals("")){
                    tonedown="2";
                }
                checkInput();
            }
        });
        secondToneThree.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                resetSecondToneImg();
                choosedToneTwo = 3;
                checkResult(secondToneThree, choosedToneTwo, rightToneTwo, false, 3);
                Logger.e("click 2 - 3");
                if(tonedown.equals("")){
                    tonedown="3";
                }
                checkInput();
            }
        });
        secondToneFour.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                resetSecondToneImg();
                choosedToneTwo = 4;
                checkResult(secondToneFour, choosedToneTwo, rightToneTwo, false, 4);
                Logger.e("click 2 - 4");
                if(tonedown.equals("")){
                    tonedown="4";
                }
                checkInput();
            }
        });
        secondToneFive.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                resetSecondToneImg();
                choosedToneTwo = 5;
                checkResult(secondToneFive, choosedToneTwo, rightToneTwo, false, 5);
                Logger.e("click 2 - 4");
                if(tonedown.equals("")){
                    tonedown="5";
                }
                checkInput();
            }
        });
    }

    private void checkResult (ImageView view, int choosed, int rig, boolean isFirstText, int tone) {
        if (choosed == rig) {
            HsSoundUtil.play(mContext, R.raw.right);
            // TODO 设置当前选择正确的标识
            if (tone == 1) view.setImageResource(R.drawable.ic_1_mode_right);
            else if (tone == 2) view.setImageResource(R.drawable.ic_2_mode_right);
            else if (tone ==3) view.setImageResource(R.drawable.ic_3_mode_right);
            else if(tone == 4) view.setImageResource(R.drawable.ic_4_mode_right);
            else if(tone == 5) view.setImageResource(R.drawable.ic_0_mode_right_s);
            AppDataBean data = mDataList.get(currentPosition);
            if (isFirstText) {
                firstToneText.setText(data.getPinyin().replace("|", " ").split(" ")[0]);
                if (lessonType == 3 || lessonType==9) {
                    mPinyinView.setText(data.getPinyin().replace("|", " ").split(" ")[0] + " " + secondToneText.getText());
                } else {
                    mPinyinView.setText(data.getPinyin().replace("|", " ").split(" ")[0]);
                }
            } else {
                secondToneText.setText(mDataList.get(currentPosition).getPinyin().replace("|", " ").split(" ")[1]);
                if (choosedToneOne == rightToneOne) {
                    mPinyinView.setText(data.getPinyin().replace("|", " "));
                } else {
                    mPinyinView.setText(data.getPhone().replace("|", " ").split(" ")[0] + " " + data.getPinyin().replace("|", " ").split(" ")[1]);
                }
            }
            AnimatorUtil.pluseAnimator(mContext, view);
        } else {
            // TODO 设置成错误的颜色
            HsSoundUtil.play(mContext, R.raw.wrong);
            if (tone == 1) view.setImageResource(R.drawable.ic_1_mode_wrong);
            else if (tone == 2) view.setImageResource(R.drawable.ic_2_mode_wrong);
            else if (tone ==3) view.setImageResource(R.drawable.ic_3_mode_wrong);
            else if(tone == 4) view.setImageResource(R.drawable.ic_4_mode_wrong);
            else if(tone == 5) view.setImageResource(R.drawable.ic_0_mode_wrong_s);
//            AnimatorUtil.shakeView(mContext, view);
            AnimatorUtil.shakeAnimator(mContext, view);
            if (isFirstText) {
                resetFirstWord();
            } else {
                resetSecondWord();
            }
        }
    }

    public void setLessonType (int lesson) {
        lessonType = lesson;
        if (lessonType == 8) {
            secondToneView.setVisibility(View.GONE);
        }
    }


    public void nextWord() {
        // TODO 数据切换，涉及到界面上文字和图片的切换
        currentPosition ++;
        saveResult(currentPosition);
        if (currentPosition < mDataList.size()) {
            updateViewData();
        } else {
            // TODO 进入下一课
            mContext.startActivity(new Intent(mContext, ToneCheckReportActivity.class).putExtra("lessonType",lessonType+""));
            ((StudyActivity)mContext).finish();
           // Utils.showDialog(mContext, R.string.next_lesson_dialog_msg, lessonType, mNextListener);
        }
    }

    public void beforeWord() {
        if (currentPosition <= 0)
            return;
        currentPosition --;
        if (currentPosition < mDataList.size()) {
            updateViewData();
        } else {
            // TODO 进入下一课. 会掉到StudyActivity页面来进行View的切换
            mNextListener.onLessonChanged(lessonType - 1);
        }
    }

    /**
     * 将做题的数据保存到数据库中, 所有项都存在，需要将原来的值取出来做累加后再写入
     */
    private void saveResult(int currentPosition) {
        AppDataBean data = mDataList.get(currentPosition-1);
            TextRecultBean tetResultInfor = UserBean.getTetResultInfor();
            tetResultInfor.setState(currentPosition);
            tetResultInfor.setTotalcount(mDataList.size());
            List<TextRecultBean.DataBean> List = tetResultInfor.getData();

            TextRecultBean.DataBean dataBean = new TextRecultBean.DataBean();
            dataBean.setWrongPy(inputcontent);
            dataBean.setRightPy(data.getPinyin().replace("|", " "));
             dataBean.setClicktone(toneUP);
          if(lessonType==8){
              dataBean.setRighttone(data.getTone());
              if(toneUP.equals(data.getTone()) && inputcontent.equals(data.getPhone())){
                  dataBean.setBooleanFlag(true);
              }else {
                  dataBean.setBooleanFlag(false);
              }
          }else {
              String[] split = data.getTone().split("|");
              dataBean.setRighttone(split[0]);
              dataBean.setRighttoneDown(split[1]);
              dataBean.setRighttoneDown(tonedown);
              if(toneUP.equals(split[0]) && inputcontent.equals(data.getPhone()) && tonedown.equals(split[1])){
                  dataBean.setBooleanFlag(true);
              }else {
                  dataBean.setBooleanFlag(false);
              }
          }

        List.add(dataBean);
        UserBean.putTetResultInfor(mContext,tetResultInfor);
          inputcontent="";
          toneUP="";
        if(currentPosition<mDataList.size()){
            edit_text_view.getText().clear();
        }


    }

    private void saveAnswerRecord(AppDataBean d) {
        AnswerRecordBean answerBean = new AnswerRecordBean();
        answerBean.setRecordID(d.getType() + "-" + d.getWeight());
        answerBean.setChinese(d.getChinese());
        answerBean.setResult(d.getTone());
        // 检查是否对
        if (lessonType == 8) {
            answerBean.setUserAnswer("" + choosedToneOne);
            if (choosedToneOne == rightToneOne) {
                answerBean.setRightTimes(1);
            } else {
                answerBean.setWrongTimes(1);
            }
        } else {
            answerBean.setUserAnswer(choosedToneOne + "|" + choosedToneTwo);
            if (choosedToneOne == rightToneOne && choosedToneTwo == rightToneTwo) {
                answerBean.setRightTimes(1);
            } else {
                answerBean.setWrongTimes(1);
            }
        }
        answerBean.setTimestamp(System.currentTimeMillis() + "");
        DBHelper.getInstance(mContext).insertAnswer(answerBean);
    }

    private void checkTone(TestResultBean da, int rt, int wt) {
        // 检查是否对
        if (lessonType == 8) {
            if (choosedToneOne == rightToneOne) {
                rt ++;
            } else {
                wt ++;
            }
        } else {
            if (choosedToneOne == rightToneOne && choosedToneTwo == rightToneTwo) {
                rt ++;
            } else {
                wt ++;
            }
        }
        da.setRightTimes(rt);
        da.setWrongTimes(wt);
    }
    /**
     * 初始化当前Lesson的数据
     */
    public void initData() {
        inputcontent="";
        toneUP="";
        mDataList = new ArrayList<AppDataBean>();
        int groupID = Utils.getRandon(0, 3);
        Logger.e("xionghy - initData: " + groupID + " -- " + lessonType);
        cursor = DBHelper.getInstance(mContext).query(DBHelper.RES_TABLE, " type=? and groupID=?", new String[]{lessonType + "", groupID + ""});
        if (cursor != null)
            Logger.e("xionghy-cursor: " + cursor.getCount());
        while(cursor.moveToNext()) {
            AppDataBean d = new AppDataBean();
            d.setChinese(cursor.getString(cursor.getColumnIndex("chinese")));
            d.setPinyin(cursor.getString(cursor.getColumnIndex("pinyin")));
            d.setPhone(cursor.getString(cursor.getColumnIndex("phone")));
            d.setTone(cursor.getString(cursor.getColumnIndex("tone")));
            d.setAudioName(cursor.getString(cursor.getColumnIndex("audioName")));
            d.setPicName(cursor.getString(cursor.getColumnIndex("picName")));
            d.setType(cursor.getInt(cursor.getColumnIndex("type")));
            d.setGroupID(cursor.getInt(cursor.getColumnIndex("groupId")));
            d.setWeight(cursor.getInt(cursor.getColumnIndex("weight")));
            mDataList.add(d);
        }
        if (mDataList.size() <= 0) {
            Logger.e("获取到的数据为空。。。。");
            return;
        }
        Logger.e("xionghy - " + mDataList.size());
        Logger.e("xionghy: " + mDataList.get(currentPosition).toString());
        updateViewData();
    }

    public void setListener(LessonProgressInterface listener) {  mListener = listener; }

    public void setNextListener(NextLessonInterface listener) { mNextListener = listener; }

    /**
     *  TODO 拿到对应的数据来进行设置，显示字符，进度条，换取对应的播放地址
     */
    private void updateViewData() {

        mPlayView.resetAll();
        resertAllToneImg();
        if (mListener != null) {
            mListener.setProgress(mDataList.size(), currentPosition);
        }
        AppDataBean data = mDataList.get(currentPosition);
        mMp3SourceDir = AppResourceMap.getMp3Fold(lessonType) + data.getAudioName().replace("|", "") + ".mp3";
        mPlayView.setStandardUrl(mMp3SourceDir);
        int picname = Integer.valueOf(data.getPhone().replace("|","").length());
        setEditTextListener(picname);

        mPinyinView.setVisibility(INVISIBLE);


//        mPlayView.playStandard();
        Logger.e("xionghy - data: " + data.toString());
        if (lessonType == 8) {
            rightToneOne = Integer.valueOf(data.getTone());
            firstToneText.setText(data.getPhone());
            mPinyinView.setText(data.getPhone());
        } else if (lessonType == 9) {
            String tones[] = data.getTone().replace("|", " ").split(" ");
            rightToneOne = Integer.valueOf(tones[0]);
            rightToneTwo = Integer.valueOf(tones[1]);
            String str = data.getPhone().replace("|"," ");
            mPinyinView.setText(str);
            String s[] = str.split(" ");
            Logger.e("xionghy - length: " + s.length);
            firstToneText.setText(s[0]);

        }
        addAnimation();
        Logger.e("xionghy - rightToneOne: " + rightToneOne + " -- " + rightToneTwo);
    }

    // 每个空间都添加一种动画
    long durationMillis = 1000, delayMillis = 0;
    private Animation chooseViewAnimation = null;
    private Animation.AnimationListener wordViewAnimListener = null;
    private void addAnimation() {
        if (chooseView != null) {
            wordViewAnimListener = new Animation.AnimationListener() {
                @Override
                public void onAnimationStart(Animation animation) {
                }
                @Override
                public void onAnimationEnd(Animation animation) {


                }
                @Override
                public void onAnimationRepeat(Animation animation) {
                }
            };
            chooseViewAnimation = scaleIn(chooseView, durationMillis, delayMillis, wordViewAnimListener);
            chooseView.post(new Runnable() {
                @Override
                public void run()  {
                    chooseViewAnimation.start();
                    mPlayView.playStandard();
                }
            });

        }
    }

    private Animation scaleIn(View view, long durationMillis, long delayMillis, Animation.AnimationListener l){
        ScaleAnimation animation = new ScaleAnimation(0, 1, 0, 1, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        animation.setDuration(durationMillis);
        animation.setStartOffset(delayMillis);
        view.setVisibility(View.VISIBLE);
        view.startAnimation(animation);
        animation.setAnimationListener(l);
        animation.cancel();
        return animation;
    }

    private void resertAllToneImg () {
        resetFirstToneImg();
        resetSecondToneImg();
    }

    private void resetText() {
        AppDataBean data = mDataList.get(currentPosition);
        if (lessonType == 1) {
            rightToneOne = Integer.valueOf(data.getTone());
            firstToneText.setText(data.getPhone());
            mPinyinView.setText(data.getPhone());
        } else if (lessonType == 9) {
            String tones[] = data.getTone().replace("|", " ").split(" ");
            rightToneOne = Integer.valueOf(tones[0]);
            rightToneTwo = Integer.valueOf(tones[1]);
            String str = data.getPhone().replace("|"," ");
            mPinyinView.setText(str);
            String s[] = str.split(" ");
            Logger.e("xionghy - length: " + s.length);
            firstToneText.setText(s[0]);
            secondToneText.setText(s[1]);
        }
    }

    private void resetFirstWord() {
        AppDataBean data = mDataList.get(currentPosition);
        if (lessonType == 1) {
            firstToneText.setText(data.getPhone());
            mPinyinView.setText(data.getPhone());
        } else if (lessonType == 9) {
            String str = data.getPhone().replace("|", " ");
            String s[] = str.split(" ");
            firstToneText.setText(s[0]);
            String txt = mPinyinView.getText().toString().split(" ")[1];
            mPinyinView.setText(s[0] + " " + txt);
        }
    }

    private void resetSecondWord() {
        AppDataBean data = mDataList.get(currentPosition);
        String str = data.getPhone().replace("|"," ");
        String s[] = str.split(" ");
        secondToneText.setText(s[1]);
        String txt = mPinyinView.getText().toString().split(" ")[0];
        mPinyinView.setText(txt + " " + s[1]);

    }

    private void resetFirstToneImg() {
        firstToneOne.setImageResource(R.drawable.ic_1_mode_initial);
        firstToneTwo.setImageResource(R.drawable.ic_2_mode_initial);
        firstToneThree.setImageResource(R.drawable.ic_3_mode_initial);
        firstToneFour.setImageResource(R.drawable.ic_4_mode_initial);
        firstToneFive.setImageResource(R.drawable.ic_0_mode_initial_s);
    }

    private void resetSecondToneImg() {
        secondToneOne.setImageResource(R.drawable.ic_1_mode_initial);
        secondToneTwo.setImageResource(R.drawable.ic_2_mode_initial);
        secondToneThree.setImageResource(R.drawable.ic_3_mode_initial);
        secondToneFour.setImageResource(R.drawable.ic_4_mode_initial);
        secondToneFive.setImageResource(R.drawable.ic_0_mode_initial_s);
    }

    public void onDestroy() {
        if (cursor != null)
            cursor.close();
        SimpleRecordUtil.getInstance(mContext).stopPlayer();
        SimpleRecordUtil.getInstance(mContext).stopRecorder();
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if(id == R.id.practise_play) {
            HsSoundUtil.playAsset(mContext, mMp3SourceDir);
        }

    }
}
